package com.wanda.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wanda.po.Customermessage;
import com.wanda.po.CustomermessageExample;
import com.wanda.po.JsonModelGeneral;
import com.wanda.service.CustomerService;

@Controller
@RequestMapping("customer")
public class CustomerController {

	@Autowired
	private CustomerService customerService;
	
	@RequestMapping("/query")
	public @ResponseBody String queryCustomer(Customermessage customermessage)throws Exception{
//		int num=(Integer) session.getAttribute("num");
//		System.out.println("==========="+num);
		System.out.println("==========queryCustomer=========");
		int n  = customerService.insert(customermessage);
		return null;
	}
	
	@RequestMapping("/List")
	public @ResponseBody JsonModelGeneral selectList(){
		CustomermessageExample customermessageExample = new CustomermessageExample();
		JsonModelGeneral jsonModel = new JsonModelGeneral();
		List<Customermessage> list = customerService.selectByExample(customermessageExample);
		jsonModel.setRows(list);
		return jsonModel;
	}
	
	@RequestMapping("/update")
	public @ResponseBody int updateCustomer(Customermessage customermessage) throws Exception{
		int n = customerService.updateByPrimaryKeySelective(customermessage);
		return n;		
	}
	@RequestMapping("/delete")
	public @ResponseBody int deleteCustomer(Integer id) throws Exception{
		int n = customerService.deleteByPrimaryKey(id);
		return n;
	}
	@RequestMapping("/select")
	public @ResponseBody JsonModelGeneral selectById(Integer id) throws Exception{
		CustomermessageExample customermessageExample = new CustomermessageExample();
		JsonModelGeneral jsonModel = new JsonModelGeneral();
		Object myobj = customerService.selectByPrimaryKey(id);
		jsonModel.setMyobj(myobj);
		return jsonModel;
	}
}
